
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#define MAX_LINE 80
#define PIPE_STDIN 0
#define PIPE_STDOUT 1

//mypipe [1] write data, mypipe[0] read from pipe
int main(  )
    {
        const char* string={"A simple message."};
        int ret,myPipe[ 2 ];
        char buffer[ MAX_LINE+1 ];
        //create the pipe
        ret=pipe( myPipe );   
        if( ret==0 )
            {
                //write the message into the pipe
                write( myPipe[ PIPE_STDOUT ],string,strlen( string ) );
                //read the message from the pipe
                ret=read( myPipe[ PIPE_STDIN ],buffer,MAX_LINE );
                //NULL terminate the string
                buffer[ ret ]=0;
                printf( "%s/n",buffer );
                
            }
        close( thePipe[ 0 ] );
        close( thePipe[ 1 ] );
        
        return 0;
    }

